package com.daou.meeting.invite;

import java.util.ArrayList;
import java.util.List;

import com.daou.smartpush.service.message.Message;
import com.daou.smartpush.service.result.Result;
import com.daou.smartpush.service.send.Sender;
import com.daou.smartpush.util.contents.Contents;

public class InviteImpl implements Invite{
	private String Host = "https://api.smartpush.co.kr:23000";
	
	@Override
	public boolean invite(List<String> memberList, String id) {
		boolean isSuccess = false;
		
		Sender sender = new Sender(Host,"/Users/seungkyupark/work/Company/MyFile/2013/SmartPush/1.3.0_KBS/ClientLog");
		
		String authRequestMsg = Message.newAuthKeyMessage()
				.userId("demo2")
				.pwd("1qaz2wsx").build();
		
		Result authResult = sender.sendAuthKey(authRequestMsg);
		
		ArrayList<String> named = new ArrayList<String>();
		
		for (String name : memberList) {
			named.add(name);
		}
		
		String namedRequestMsg = null;
		
		try {//"[회의참석 메세지] " + id + " 님이 회의에 초대하였습니다." 
			namedRequestMsg = Message.newNamdMessage()
					.authKey(authResult.getAuthKey())
					.appkey("발송 앱 Appkey")
					.message("[회의참석 메세지] " + id + " 님이 회의에 초대하였습니다.")
					.pushType(Contents.PAYLOAD_PUSHTYPE_ALL)
					.sendType(Contents.PAYLOAD_SENDTYPE_NORMAL)
					.receiveType(Contents.PAYLOAD_RECEIVETYPE_MADDRESS)
					.targetList(named)
					.cutOption(Contents.PAYLOAD_CUTOPTION_YES).build();
		} catch (Exception e) {
			System.out.println("Named Message Setting Error");
		}
		
		Result namedResult = sender.sendNamed(namedRequestMsg);
		
		if ("200".equals(namedResult.getResultCode())) {
			isSuccess = true;
		} else {
			isSuccess = false;
		}
		return isSuccess;
	}
	
}
